@extends('layouts.back_stage')
@section('content')
    <style>
        .shopBg{background:#fff;overflow: hidden;margin:20px 0 10px 0;}
        .tableBg{padding:30px;background:#fff;margin-top:30px;overflow: hidden;}
        .input-item{width:350px;padding-right: 0;margin-right:10px;}
        .el-table--mini th{padding:0;}
        .el-form-item{width:50%;float:left;margin-bottom:5px;}
        .input-info{width:270px;}
        .el-dialog__body{display:inline-block;}
        .input-size,.input-nums{width:45px;float:left;margin-right:10px;}
        .input-size .el-input__inner,.input-nums .el-input__inner{padding:0;text-align:center;}
        .el-autocomplete-suggestion.el-popper.is-loading{display:none;}

        .listDiv,.listUl,.listOl{width:100%;height:35px;margin-bottom:0;}
        .listUl li,.listOl li{width:7%;height:35px;border:1px solid #ccc;float:left;line-height:35px;text-align:center;border-right:0;}
        .listUl li{border-bottom:0;}
        .listUl li:last-child,.listOl li:last-child{border-right:1px solid #ccc;}
        ::-webkit-scrollbar {height: 8px;}
        .el-table__footer-wrapper tbody td, .el-table__header-wrapper tbody td{color:red;}
        [v-cloak] {display: none;}
    </style>
    <div class="container">
        <div style="padding:20px 20px 20px 0;overflow:hidden;"><h3 class="statusLi" abc="{{$is_ack}}" style="float:left;">手工退货单</h3></div>
        <!-- 主体-->
        <div class="page-body">
            <div class="row app" id="shopInfos" v-cloak>
                <div class="col-md-12 row row-table-box">
                    <div class="shopBg">
                        <div class="row" style="padding:10px 30px;background:#fff;margin-top:10px;">
                            <label style="margin-right:3px;">单 据 号：</label>
                            <el-input v-model="order_num" class="input-item" placeholder="单据号" size="small" :disabled="true"></el-input>
                            <label>退货仓库：</label>
                            <el-select v-model="fact_type_id" class="input-item" filterable placeholder="请选择退货仓库(必)" size="small" :disabled="sendType">
                                <el-option v-for="item in options1" :key="item.id" :label="item.factory_type" :value="item.id"></el-option>
                            </el-select>
                        </div>
                        <div class="row" style="padding:10px 30px;background:#fff;">
                            <label style="margin-right:22px;">类 别：</label>
                            <el-radio-group v-model="customer_type" size="small" style="width:360px;" :disabled="sendType" @change="radioCha">
                                <el-radio label="2" border>客户</el-radio>
                                <el-radio label="1" border>店铺</el-radio>
                            </el-radio-group>
                            <div style="display: inline-block;" v-show="shopShow">
                                <label>退货店铺：</label>
                                <el-select v-model="customer_id" class="input-item" filterable placeholder="请选择退货店铺(必)" size="small" :disabled="sendType">
                                    <el-option v-for="item in options2" :key="item.id" :label="item.shop_name" :value="item.id"></el-option>
                                </el-select>
                            </div>
                            <div style="display: inline-block;" v-show="peopleShow">
                                <label>客户名称：</label>
                                <el-select v-model="customer_id" class="input-item" filterable placeholder="请选择客户(必)" size="small" :disabled="sendType">
                                    <el-option v-for="item in options4" :key="item.id" :label="item.customer_name" :value="item.id"></el-option>
                                </el-select>
                            </div>
                        </div>
                        <div class="row" style="padding:10px 30px;background:#fff;margin-bottom:10px;">
                            <label>销售季节：</label>
                            <el-select v-model="season_id" class="input-item" filterable placeholder="请选择销售季节(必)" @change="changeLabel" size="small" :disabled="sendType">
                                <el-option v-for="item in options3" :key="item.id" :label="item.sale_season" :value="item.id"></el-option>
                            </el-select>
                            <label>退货类型：</label>
                            <el-select v-model="deliver_type_id" class="input-item" filterable placeholder="请选择发货类型(必)" size="small" :disabled="sendType">
                                <el-option v-for="item in options5" :key="item.id" :label="item.name" :value="item.id"></el-option>
                            </el-select>
                        </div>
                        <div class="row" style="padding:10px 30px;background:#fff;margin-bottom:10px;">
                            <label style="float:left;margin-right:25px;">备 注：</label>
                            <el-input v-model="remark" border="0" style="width:785px;display:inline-block;" class="lis-textarea" type="textarea" :autosize="{ minRows: 1, maxRows: 350}" maxlength="30" placeholder="请填写备注(30以内字符)" :disabled="sendType"></el-input>
                        </div>
                    </div>
                    <div class="tableBg" style="margin-top:10px;">
                        <div v-show="souType">
                            <label style="margin-right:3px;">款号：</label>
                            <el-autocomplete v-model.trim="girard" :trigger-on-focus="false" :fetch-suggestions="querySearchAsync" size="small" placeholder="请输入款号" @select="handleSelect"></el-autocomplete>
                            <el-button type="primary" size="small" @click="addInfos">添加</el-button>
                        </div>
                        <el-table :data="tableInfo" size="mini" border style="margin-top:20px;" :summary-method="getSummaries" show-summary>
                            <el-table-column prop="year" width="55" label="年份" :resizable='false'></el-table-column>
                            <el-table-column prop="season" width="55" label="季节" :resizable='false'></el-table-column>
                            <el-table-column prop="girard" min-width="100" label="款号" :resizable='false'></el-table-column>
                            <el-table-column prop="color" min-width="70" label="颜色" :resizable='false'></el-table-column>
                            <el-table-column prop="price" label="吊牌价/元" align="right" width="130" :resizable='false'></el-table-column>
                            <el-table-column prop="disPrice" label="折扣价/元" align="right" width="130" :resizable='false'></el-table-column>
                            <el-table-column prop="discount" label="折扣" width="50" :resizable='false'></el-table-column>

                            <el-table-column v-for="item in sizeGr"  :label="item.key76" width="70" :resizable='false'>
                                <el-table-column :label="item.key75" width="70" :resizable='false'>
                                    <el-table-column :label="item.key79" width="70" :resizable='false'>
                                        <el-table-column :label="item.key154" width="70" :resizable='false'>
                                            <el-table-column :label="item.key146" width="70" :resizable='false'>
                                                <el-table-column :label="item.key161" width="70" :resizable='false'>
                                                    <el-table-column :label="item.key77" width="70" :resizable='false'>
                                                        <el-table-column :prop="item.key_0" :label="item.key140" width="70" :resizable='false'></el-table-column>
                                                    </el-table-column>
                                                </el-table-column>
                                            </el-table-column>
                                        </el-table-column>
                                    </el-table-column>
                                </el-table-column>
                            </el-table-column>

                            <el-table-column prop="count" label="合计/件" width="70" :resizable='false'></el-table-column>
                            <el-table-column prop="disCount" label="折扣金额/元" align="right" width="120" :resizable='false'></el-table-column>
                            <el-table-column prop="cardCount" label="吊牌金额/元" align="right" width="120" :resizable='false'></el-table-column>
                            <el-table-column label="操作" fixed="right" width="100" :resizable='false'>
                                <template slot-scope="scope">
                                    <div v-if="scope.row.is_ack==='1'">-</div>
                                    <div v-else>
                                        <el-button type="text" size="small" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                                        <el-button type="text" size="small" @click="handleDel(scope.row)">删除</el-button>
                                    </div>
                                </template>
                            </el-table-column>
                        </el-table>
                        <el-button type="primary" size="small" @click="overMake" style="margin-top:20px;float:right;" v-show="souType">制单完成</el-button>
                    </div>
                </div>
                <el-dialog title="添加信息" :visible.sync="showBox" class="add-box" width="60%">
                    <el-form :model="addAct" width="500">
                        <el-form-item label="年份" label-width="100px">
                            <el-input v-model="addAct.year" class="input-info" size="small" :disabled="true"></el-input>
                        </el-form-item>
                        <el-form-item label="季节" label-width="100px">
                            <el-input v-model="addAct.season" class="input-info" size="small" :disabled="true"></el-input>
                        </el-form-item>
                        <el-form-item label="款号" label-width="100px">
                            <el-input v-model="addAct.girard" class="input-info" size="small" :disabled="true"></el-input>
                        </el-form-item>

                        <el-form-item label="吊牌价/元" label-width="100px">
                            <el-input v-model="addAct.price" class="input-info" size="small" :disabled="true"></el-input>
                        </el-form-item>
                        <el-form-item label="折扣" label-width="100px">
                            <el-input v-model="addAct.discount" class="input-info" size="small" :disabled="true"></el-input>
                        </el-form-item>
                        <el-form-item label="颜色" label-width="100px">
                            <el-select v-model="addAct.color" filterable placeholder="请选择颜色(必)" size="small" class="input-info" :disabled="colorFlag" @change="chooseSelect">
                                <el-option v-for="item in colors" :key="item.value" :label="item.label" :value="item.value"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="尺码" label-width="100px" style="width:100%;">
                            <el-input v-for="(item1,index1) in sizes" :key="index1" v-model="sur[index1]"  class="input-size" size="small" :disabled="true"></el-input>
                        </el-form-item>
                        <el-form-item label="退货数量/件" label-width="100px" style="width:100%;" v-show="cargo">
                            <el-input v-for="(item2,index2) in amounts" :key="index2" v-model="cur[index2]" maxlength="4" class="input-nums" size="small" @keyup.native="proving1(this,index2)"></el-input>
                        </el-form-item>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="showBox = false" size="small">取 消</el-button>
                        <el-button type="primary" @click="sureBtn" size="small">确 定</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
        <!-- /主体-->
    </div>
    <script>
        new Vue({
            el: '#shopInfos',
            data:{

                customer_type: '2',
                shopShow:false,
                peopleShow:true,

                sizeGr:[],//尺码信息
                is_ack:'{{$is_ack}}',
                options1: [],//退货仓库
                options2: [],//客 户
                options3: [],//销售季节
                options4: [],//客户
                options5: [],//退货类型

                order_num:'',//单据号
                fact_type_id:'',//退货仓库
                customer_id:'',//退货店铺or客户
                season_id:'',//销售季节id
                season:'',//销售季节名称
                deliver_type_id:'',//退货类型
                remark:'',//备注
                sendType:false,//退货仓库,收货店铺,销售季节,备注
                souType:true,//搜索,制单完成

                tableInfo:[], //表格数据

                girard:'',//搜索款号
                showBox:false,//添加弹框显示隐藏
                colorFlag:false,//颜色禁选
                addAct:{
                    year:'',//年份
                    season:'',//季节
                    girard:'',//款号
                    color:'',//颜色
                    price:'',//吊牌价
                    discount:'',//折扣
                },
                colors: [],//颜色
                sizes: [],//尺码
                amounts:[],//数量
                cargo:false,//退数量隐藏
                colorFlag:false,//颜色disabled

                //sizego:false,//尺码隐藏

                sur:[],//尺码保存取值
                cur:[],//配货数量保存取值

                regs:false,//判断正整数
                girardNum:'',//款号种类合计

                overFlag:true,
                delFlag:true,
                editFlag:true,
            },
            mounted(){
                console.log(this.is_ack)
                if(this.is_ack==0){
                    this.sendType=false;
                    this.souType=true;
                }else if(this.is_ack==1){
                    this.sendType=true;
                    this.souType=false;
                }
                this.common();
                this.basic();
                this.listInfo();
            },
            methods:{
                /*尺码数据*/
                common(){
                    var that=this;
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                        },
                        type: 'post',
                        url: '/distribution/sizeGroupHead',
                        data: {
                            type:1,
                        },
                        success: function (data) {
                            //console.log(data);
                            if(data.result.success){
                                that.sizeGr=data.content.vertical;
                            }else{
                                that.$notify.error({
                                    title: '提示',
                                    message: data.result.errorMsg,
                                });
                            }
                        }
                    });
                },
                /*基本信息*/
                basic(){
                    var that=this;
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                        },
                        type: 'post',
                        url: '/distribution/return-base-info',
                        data: {
                            id:'{{$id}}'
                        },
                        success: function (data) {
                            //console.log(data);
                            if(data.result.success){
                                that.order_num=data.content.order_num;
                                that.options1=data.content.data.fact_type;//仓库
                                that.options2=data.content.data.shop_lists;
                                that.options3=data.content.data.sale_season;//季节
                                that.options4=data.content.data.customer;//客户
                                that.options5=data.content.data.deliver_type;//类型

                                that.fact_type_id=data.content.fact_type_id;
                                if(data.content.customer_type==1){
                                    that.shopShow=true;
                                    that.peopleShow=false;
                                }else if(data.content.customer_type==2){
                                    that.shopShow=false;
                                    that.peopleShow=true;
                                }
                                that.customer_type=data.content.customer_type;
                                that.customer_id=data.content.customer_id;
                                that.season=data.content.season;
                                that.season_id=data.content.season_id;
                                that.deliver_type_id=data.content.deliver_type_id;
                                that.remark=data.content.remark;
                            }else{
                                that.$notify.error({
                                    title: '提示',
                                    message: data.result.errorMsg,
                                });
                            }
                        }
                    });
                },
                /*单选改变*/
                radioCha(val){
                    if(val==1){
                        this.shopShow=true;
                        this.peopleShow=false;
                    }else if(val==2){
                        this.shopShow=false;
                        this.peopleShow=true;
                    }
                    this.customer_id='';
                    this.customer_type=val;
                },
                /*获取季节名称*/
                changeLabel(val){
                    let obj = {};
                    obj = this.options3.find((item)=>{
                        return item.id === val;
                    });
                    this.season=obj.sale_season;
                },
                /*列表数据*/
                listInfo(){
                    var that=this;
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                        },
                        type: 'post',
                        url: '/distribution/girard-ack-info',
                        data: {
                            id:'{{$id}}'
                        },
                        success: function (data) {
                            //console.log(data);
                            if(data.result.success){
                                if(data.content.length>0){
                                    that.sendType=true;
                                }else{
                                    that.sendType=false;
                                }
                                var opt=[];
                                let girardArr=[];
                                for(var value of data.content){
                                    if(girardArr.indexOf(value.girard)==-1){
                                        girardArr.push(value.girard)
                                    };
                                    var cvs=0;
                                    for(var cv=0;cv<value.nums.length;cv++){
                                        if(value.nums[cv]==''){
                                            value.nums[cv]=0;
                                        }
                                        cvs+=Number(value.nums[cv]);
                                    }
                                    var oneNum=0;
                                    var twoNum=0;
                                    if(value.nums.length==9 && value.price.indexOf("/")!=-1){
                                        for(var cc=0;cc<value.nums.length;cc++){
                                            if(value.nums[cc]==''){
                                                value.nums[cc]=0;
                                            }
                                            if(cc<7){
                                                oneNum+=Number(value.nums[cc]);
                                            }else{
                                                twoNum+=Number(value.nums[cc]);
                                            }
                                        }
                                    }
                                    opt.push({
                                        'id':value.id,
                                        'year':value.year,
                                        'season':value.season,
                                        'girard':value.girard,
                                        'num':value.nums,
                                        'color':value.color,
                                        'price':value.price,
                                        'disPrice':that.getMon( value.price , value.discount),
                                        'discount':value.discount,
                                        'size_group':value.size_group,
                                        'count':cvs,
                                        'disCount':that.getDon( value.price , value.discount , oneNum , twoNum , cvs),
                                        'cardCount':that.getCou(value.price , oneNum , twoNum , cvs),
                                        'status':data.content.status,
                                        'is_ack':that.is_ack,
                                    })
                                }
                                that.girardNum=girardArr.length;
                                that.tableInfo = opt;
                            }else{
                                that.$notify.error({
                                    title: '提示',
                                    message: data.result.errorMsg,
                                });
                            }
                        }
                    });
                },
                /*折扣*/
                getMon(money,dis){
                    if(money.indexOf("/")!=-1){
                        let priArr=money.split("/");
                        let disOne=(priArr[0]*dis).toFixed(2);
                        let disTwo=(priArr[1]*dis).toFixed(2);
                        return disOne+'/'+disTwo
                    }else{
                        return (money*dis).toFixed(2);
                    }
                },
                /*总折扣*/
                getDon(money,dis,n1,n2,n3){
                    if(money.indexOf("/")!=-1){
                        let priArr=money.split("/");
                        let disOne=(priArr[0]*dis*n1);
                        let disTwo=(priArr[1]*dis*n2);
                        return (Number(disOne) + Number(disTwo)).toFixed(2);
                    }else{
                        return (money*dis*n3).toFixed(2);
                    }
                },
                /*总金额*/
                getCou(money,n1,n2,n3){
                    if(money.indexOf("/")!=-1){
                        let priArr=money.split("/");
                        let disOne=(priArr[0]*n1);
                        let disTwo=(priArr[1]*n2);
                        return (Number(disOne) + Number(disTwo)).toFixed(2);
                    }else{
                        return (money*n3).toFixed(2);
                    }
                },
                /*合计*/
                getSummaries(param) {
                    var that=this;
                    const { columns, data } = param;
                    const sums = [];
                    columns.forEach((column, index) => {
                        if (index === 0) {
                            sums[index] = '合计';
                            return;
                        }
                        const values = data.map(item => Number(item[column.property]));
                        switch (column.property) {
                            case 'girard':
                                sums[index] = that.girardNum;
                                break;
                            case 'count':
                                sums[index] = values.reduce((prev, curr) => {
                                    const value = Number(curr);
                                    if (!isNaN(value)) {
                                        return prev + curr;
                                    } else {
                                        return prev;
                                    }
                                }, 0);
                                break;
                            case 'disCount':
                                sums[index] = values.reduce((prev, curr) => {
                                    const value = Number(curr);
                                    if (!isNaN(value)) {
                                        return ( parseFloat(prev) + parseFloat(curr) ).toFixed(2);
                                    } else {
                                        return parseFloat(prev).toFixed(2);
                                    }
                                }, 0);
                                break;
                            case 'cardCount':
                                sums[index] = values.reduce((prev, curr) => {
                                    const value = Number(curr);
                                    if (!isNaN(value)) {
                                        return ( parseFloat(prev) + parseFloat(curr) ).toFixed(2);
                                    } else {
                                        return parseFloat(prev).toFixed(2);
                                    }
                                }, 0);
                                break;
                            default:
                                break;
                        }
                    });
                    return sums
                },
                /*点击添加按钮*/
                addInfos(){
                    var that=this;
                    if(this.fact_type_id==''){
                        this.$notify.error({
                            title: '提示',
                            message: "请选择退货仓库",
                        });
                        return false;
                    }
                    if(this.customer_type==1 && this.customer_id==''){
                        this.$notify.error({
                            title: '提示',
                            message: "请选择退货店铺",
                        });
                        return false;
                    }
                    if(this.customer_type==2 && this.customer_id==''){
                        this.$notify.error({
                            title: '提示',
                            message: "请选择客户",
                        });
                        return false;
                    }
                    if(this.season_id==''){
                        this.$notify.error({
                            title: '提示',
                            message: "请选择销售季节",
                        });
                        return false;
                    }
                    if(this.deliver_type_id==''){
                        this.$notify.error({
                            title: '提示',
                            message: "请选择发货类型",
                        });
                        return false;
                    }
                    if(this.girard==''){
                        this.$notify.error({
                            title: '提示',
                            message: "请输入款号再添加",
                        });
                        return false;
                    }
                    that.addAct.color=''; //颜色
                    that.amounts=[]; //退货数据
                    that.cargo=false; //退货数量隐藏
                    that.colorFlag=false; //颜色disabled
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                        },
                        type: 'post',
                        url: '/distribution/girard-color-size',
                        data: {
                            id:'{{$id}}',
                            is_modify:'{{$is_modify}}',
                            fact_type_id:that.fact_type_id,//退货仓库
                            customer_type :that.customer_type,//店铺类型or客户类型
                            customer_id:that.customer_id,//退货店铺or客户
                            season_id:that.season_id,//销售季节id
                            season:that.season,//销售季节名称
                            deliver_type_id:that.deliver_type_id,//退货类型
                            remark:that.remark,//备注
                            girard:that.girard,
                            {{--is_modify:'{{$is_modify}}',--}}

                        },
                        success: function (data) {
                            //console.log(data);
                            if(data.result.success){
                                that.addAct.year=data.content.year;
                                that.addAct.season=data.content.season;
                                that.addAct.girard=data.content.girard;
                                that.addAct.price=data.content.price;
                                that.addAct.discount=data.content.discount;
                                var optColor=[];
                                for(var j =0;j<data.content.color.length;j++){
                                    optColor.push({
                                        'value':data.content.color[j],
                                        'label':data.content.color[j],
                                    })
                                }
                                var optSizes=[];
                                that.sur=[];
                                for(var x =0;x<data.content.size_group.length;x++){
                                    that.sur.push(data.content.size_group[x]);
                                    optSizes.push(data.content.size_group[x])
                                }
                                that.sizes=optSizes;
                                that.colors=optColor;
                                that.showBox = true;
                            }else{
                                that.sur=[];
                                that.$notify.error({
                                    title: '提示',
                                    message: data.result.errorMsg,
                                });
                            }
                        }
                    });
                },
                /*点击颜色*/
                chooseSelect(item){
                    var that=this;
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                        },
                        type: 'post',
                        url: '/distribution/girard-color-num',
                        data: {
                            id:'{{$id}}',
                            girard:that.girard,
                            color:item
                        },
                        success: function (data) {
                            //console.log(data);
                            if(data.result.success){
                                var aptAmounts=[];
                                that.cur=[];
                                for(var x =0;x<data.content.num.length;x++){
                                    that.cur.push(data.content.num[x]);
                                    aptAmounts.push(data.content.num[x])
                                }
                                that.amounts=aptAmounts;
                                that.cargo=true;
                            }else{
                                that.cur=[];
                                that.amounts=[];
                                that.cargo=false;
                                that.$notify.error({
                                    title: '提示',
                                    message: data.result.errorMsg,
                                });
                            }
                        }
                    });
                },
                /*点击确定*/
                sureBtn(){
                    var that=this;
                    if(that.addAct.color==''){
                        that.$notify.error({
                            title: '提示',
                            message: "请选择颜色填写数量再确定",
                        });
                        return false;
                    }
                    if(that.regs==true){
                        var surs=this.sur;//尺码保存取值
                        var curs=this.cur;//退货数量保存取值
                        var nm=0;
                        var bm=curs.length;
                        for(var z=0;z<curs.length;z++){
                            if( curs[z]==0){
                                nm++;
                            }
                        }
                        if(Number(bm)-Number(nm)<=0){
                            that.$notify.error({
                                title: '提示',
                                message: "退货数量不能全为零",
                            });
                            return false;
                        }
                        $.ajax({
                            headers: {
                                'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                            },
                            type: 'post',
                            url: '/distribution/return-girard-confirm',
                            data: {
                                id:'{{$id}}',
                                is_modify:'{{$is_modify}}',
                                girard:that.addAct.girard,
                                color:that.addAct.color,
                                size:surs.join(","),
                                num:curs.join(",")
                            },
                            success: function (data) {
                                //console.log(data);
                                if(data.result.success){
                                    that.$notify.success({
                                        title: '提示',
                                        message: "添加成功",
                                    });
                                    that.listInfo();
                                    that.showBox=false;
                                }else{
                                    that.$notify.error({
                                        title: '提示',
                                        message: data.result.errorMsg,
                                    });
                                }
                            }
                        });
                    }else{
                        that.$notify.error({
                            title: '提示',
                            message: "请填写正确的数字",
                        });
                    }
                },
                /*远程搜索*/
                querySearchAsync(queryString, cb) {
                    if(this.fact_type_id==''){
                        $(".el-autocomplete-suggestion.el-popper.is-loading").hide();
                        this.$notify.error({
                            title: '提示',
                            message: "请选择退货仓库再输入款号添加",
                        });
                        this.girard='';
                    }else if(this.customer_type==1 && this.customer_id==''){
                        $(".el-autocomplete-suggestion.el-popper.is-loading").hide();
                        this.$notify.error({
                            title: '提示',
                            message: "请选择收货店铺再输入款号添加",
                        });
                        this.girard='';
                    }else if(this.customer_type==2 && this.customer_id==''){
                        $(".el-autocomplete-suggestion.el-popper.is-loading").hide();
                        this.$notify.error({
                            title: '提示',
                            message: "请选择客户再输入款号添加",
                        });
                        this.girard='';
                    }else if(this.season_id==''){
                        $(".el-autocomplete-suggestion.el-popper.is-loading").hide();
                        this.$notify.error({
                            title: '提示',
                            message: "请选择销售季节再输入款号添加",
                        });
                        this.girard='';
                    }else{
                        var that=this;
                        $.ajax({
                            headers: {
                                'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                            },
                            type: 'post',
                            url: '/distribution/thd-pro-girard',
                            data: {
                                fact_type_id:that.fact_type_id,
                                customer_id:that.customer_id,
                                season_id:that.season_id,
                                season:that.season,
                                remark:that.remark,
                                girard:queryString
                            },
                            success: function (data) {
                                if(data.result.success){
                                    var results=[];
                                    for(var i=0;i<data.content.length;i++){
                                        results.push({
                                            'value':data.content[i]
                                        })
                                    }
                                    clearTimeout(this.timeout);
                                    this.timeout = setTimeout(() => {
                                        cb(results);
                                    }, 2000 * Math.random());
                                    $(".el-autocomplete-suggestion.el-popper.is-loading").show();
                                }else{
                                    that.$notify.error({
                                        title: '提示',
                                        message: data.result.errorMsg,
                                    });
                                }
                            }
                        });
                    }
                },
                /*点击选项*/
                handleSelect(item) {
                    //console.log(item);
                },
                proving1(that,index){
                    //console.log(index)
//                    that.cur[index]=that.cur[index].replace(/[^\.\d]/g,'');
//                    that.cur[index]=that.cur[index].replace('.','');
                },
                /*编辑*/
                handleEdit(index,row){
                    var that=this;
                    const h = this.$createElement;
                    this.$msgbox({
                        title: '提示',
                        message: h('p', null, [
                            h('span', null, '确定编辑该款退货数量?'),
                        ]),
                        showCancelButton: true,
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning',
                        beforeClose: (action, instance, done) => {
                            if (action === 'confirm') {
                                if(that.editFlag==true){
                                    that.editFlag=false;
                                    $.ajax({
                                        headers: {
                                            'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                                        },
                                        type: 'post',
                                        url: '/distribution/girard-color-num',
                                        data: {
                                            id:'{{$id}}',
                                            is_modify:'{{$is_modify}}',
                                            girard:row.girard,
                                            color:row.color,
                                        },
                                        success: function (data) {
                                            //console.log(data);
                                            if(data.result.success){
                                                that.addAct.year=row.year;
                                                that.addAct.season=row.season;
                                                that.addAct.girard=row.girard;
                                                that.addAct.price=row.price;
                                                that.addAct.discount=row.discount;
                                                that.addAct.color=row.color;
                                                that.colorFlag=true;

                                                var optSizes=[];
                                                that.sur=[];
                                                for(var x1 =0;x1<data.content.size.length;x1++){
                                                    that.sur.push(data.content.size[x1]);
                                                    optSizes.push(data.content.size[x1])
                                                }
                                                that.sizes=optSizes;
                                                that.cargo=true;

                                                var aptAmounts=[];
                                                that.cur=[];
                                                for(var x2 =0;x2<data.content.num.length;x2++){
                                                    that.cur.push(data.content.num[x2]);
                                                    aptAmounts.push(data.content.num[x2])
                                                }
                                                that.amounts=aptAmounts;
                                                that.showBox = true;
                                                that.listInfo();
                                                done();
                                                that.editFlag=true;
                                            }else{
                                                that.$notify.error({
                                                    title: '错误',
                                                    message: data.result.errorMsg
                                                });
                                                that.editFlag=true;
                                            }
                                        }
                                    })
                                }
                            } else {
                                done();
                            }
                        }
                    }).then(action => {

                    });
                },
                /*删除*/
                handleDel(row){
                    var that=this;
                    const h = this.$createElement;
                    this.$msgbox({
                        title: '提示',
                        message: h('p', null, [
                            h('span', null, '是否删除此款号下的数量?'),
                        ]),
                        showCancelButton: true,
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning',
                        beforeClose: (action, instance, done) => {
                            if (action === 'confirm') {
                                if(that.delFlag==true){
                                    that.delFlag=false;
                                    $.ajax({
                                        headers: {
                                            'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                                        },
                                        type: 'post',
                                        url: '/distribution/girard-color-num-del',
                                        data: {
                                            id:'{{$id}}',
                                            is_modify:'{{$is_modify}}',
                                            girard:row.girard,
                                            color:row.color,
                                        },
                                        success: function (data) {
                                            //console.log(data);
                                            if(data.result.success){
                                                that.$notify.success({
                                                    title: '提示',
                                                    message: data.content
                                                });
                                                done();
                                                that.listInfo();
                                                that.delFlag=true;
                                            }else{
                                                that.$notify.error({
                                                    title: '错误',
                                                    message: data.result.errorMsg
                                                });
                                                that.delFlag=true;
                                            }
                                        }
                                    })
                                }
                            } else {
                                done();
                            }
                        }
                    }).then(action => {

                    });
                },
                overMake(){
                    if(this.tableInfo.length<=0){
                        this.$notify.error({
                            title: '提示',
                            message: "至少添加一条数据",
                        });
                        return false;
                    }
                    if(this.fact_type_id==''){
                        this.$notify.error({
                            title: '提示',
                            message: "请选择退货仓库",
                        });
                        return false;
                    }
                    if(this.customer_type==1 && this.customer_id==''){
                        this.$notify.error({
                            title: '提示',
                            message: "请选择收货店铺",
                        });
                        return false;
                    }
                    if(this.customer_type==2 && this.customer_id==''){
                        this.$notify.error({
                            title: '提示',
                            message: "请选择客户",
                        });
                        return false;
                    }
                    if(this.season_id==''){
                        this.$notify.error({
                            title: '提示',
                            message: "请选择销售季节",
                        });
                        return false;
                    }
                    if(this.deliver_type_id==''){
                        this.$notify.error({
                            title: '提示',
                            message: "请选择退货类型",
                        });
                        return false;
                    }
                    var that=this;
                    const h = this.$createElement;
                    this.$msgbox({
                        title: '提示',
                        message: h('p', null, [
                            h('span', null, '是否确认完成制单?'),
                        ]),
                        showCancelButton: true,
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning',
                        beforeClose: (action, instance, done) => {
                            if (action === 'confirm') {
                                if(that.overFlag==true){
                                    that.overFlag=false;
                                    $.ajax({
                                        headers: {
                                            'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                                        },
                                        type: 'post',
                                        url: '/distribution/pfth-complete',
                                        data: {
                                            id:'{{$id}}',
                                            is_modify:'{{$is_modify}}',
                                            fact_type_id:that.fact_type_id,
                                            customer_id:that.customer_id,
                                            season_id:that.season_id,
                                            season:that.season,
                                            deliver_type_id:that.deliver_type_id,
                                            remark:that.remark,
                                        },
                                        success: function (data) {
                                            //console.log(data);
                                            if(data.result.success){
                                                done();
                                                that.$notify.success({
                                                    title: '提示',
                                                    message: "操作成功"
                                                });
                                                that.overFlag=true;
                                                setTimeout(function () {
                                                    window.location.href='/distribution/goods-return-list';
                                                },1000)
                                            }else{
                                                that.$notify.error({
                                                    title: '提示',
                                                    message: data.result.errorMsg,
                                                });
                                                that.overFlag=true
                                            }
                                        }
                                    });
                                }
                            } else {
                                done();
                            }
                        }
                    }).then(action => {

                    });
                }
            },
            watch : {
                /*款号字母大写*/
                girard:function(val) {
                    this.girard = val.toUpperCase();
                },
                cur:function (val) {
                    var reg=/^([1-9]\d*|[0]{1,1})$/;
                    for(let s=0; s<val.length ;s++){
                        if(!reg.test(val[s])){
                            this.regs=false;
                            return false;
                        }else{
                            this.regs=true;
                        }
                    }
                }
            }
        });
    </script>
@endsection
